<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css?v=4.4.0}"/>
    <!-- Morris -->
    <link href="../../resource/hotui/css/plugins/morris/morris-0.4.3.min.css"
          rel="stylesheet" th:href="@{/resource/hotui/css/plugins/morris/morris-0.4.3.min.css}">
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}" rel="stylesheet"/>

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .daterangepicker {
            z-index: 999999999 !important;
        }

        .nav-tabs input {
            width: 20px;
            height: 23px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="orderId">订单号：</label>
                                <input type="text" class="form-control input-sm mb10" id="orderId" th:value="*{orderId}"
                                       name="orderId" placeholder="订单号" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="orderId">下单用户：</label>
                                <input type="text" class="form-control input-sm mb10" id="userKey" th:value="*{userKey}"
                                       name="userKey" placeholder="手机/姓名" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="parentMobile">推荐人手机：</label>
                                <input type="text" class="form-control input-sm mb10" id="parentMobile"
                                       th:value="*{parentMobile}"
                                       name="parentMobile" placeholder="推荐人手机" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="orderId">收件人：</label>
                                <input type="text" class="form-control input-sm mb10" id="receiver"
                                       th:value="*{receiver}" name="receiver" placeholder="姓名/手机"
                                       style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="goodsKey">商品：</label>
                                <input type="text" class="form-control input-sm mb10" id="goodsKey" name="goodsKey"
                                       th:value="*{goodsKey}" placeholder="商品名称/编号"/>
                            </div>
                            <div class="form-group m-r-sm" sec:authorize="hasRole('ADMIN')">
                                <label class=" control-label" for="shopTitle">所属店铺：</label>
                                <input class="form-control input-sm mb10" id="shopTitle" name="shopTitle"
                                       placeholder="店铺名称"
                                       th:value="*{shopTitle}" type="text"/>
                            </div>
                        </div>
                        <p style="height: 20px;"></p>
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="status">订单状态：</label>
                                <select class="form-control input-sm mb10" id="status" name="status">
                                    <option th:selected="*{status==-1}" value="-1">请选择</option>
                                    <option th:selected="*{status==0}" value="0">活动</option>
                                    <option th:selected="*{status==1}" value="1">交易关闭</option>
                                    <option th:selected="*{status==2}" value="2">交易取消</option>
                                    <option th:selected="*{status==3}" value="3">交易完成</option>
                                </select>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="payStatus">支付状态：</label>
                                <select class="form-control input-sm mb10" id="payStatus" name="payStatus">
                                    <option th:selected="*{payStatus==-1}" value="-1">请选择</option>
                                    <option th:selected="*{payStatus==0}" value="0">待支付</option>
                                    <option th:selected="*{payStatus==1}" value="1">已支付</option>
                                    <option th:selected="*{payStatus==2}" value="2">支付超时</option>
                                </select>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="payStatus">发货状态：</label>
                                <select class="form-control input-sm mb10" id="deliverStatus" name="deliverStatus">
                                    <option th:selected="*{deliverStatus==-1}" value="-1">请选择</option>
                                    <option th:each="ds:${deliverStatuses}" th:value="${ds.code}"
                                            th:text="${ds.desc}" th:selected="${ds.code==condition.deliverStatus}"
                                            value="0">待发货
                                    </option>
                                </select>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="payStatus">售后状态：</label>
                                <select class="form-control input-sm mb10" id="afterSaleStatus" name="afterSaleStatus">
                                    <option th:selected="*{afterSaleStatus==-1}" value="-1">请选择</option>
                                    <option th:selected="*{afterSaleStatus==0}" value="0">取消售后</option>
                                    <option th:selected="*{afterSaleStatus==1}" value="1">售后申请中</option>
                                    <option th:selected="*{afterSaleStatus==2}" value="2">等待买家退货</option>
                                    <option th:selected="*{afterSaleStatus==3}" value="3">退款中</option>
                                    <option th:selected="*{afterSaleStatus==4}" value="4">售后完成</option>
                                    <option th:selected="*{afterSaleStatus==5}" value="5">拒绝售后</option>
                                    <option th:selected="*{afterSaleStatus==6}" value="6">买家退货等待确认</option>
                                    <option th:selected="*{afterSaleStatus==7}" value="7">待退款</option>
                                    <option th:selected="*{afterSaleStatus==8}" value="8">售后失败</option>
                                </select>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="payTimePick">支付时间：</label>
                                <input readonly type="text" class="form-control input-sm mb10 data-range-pick"
                                       id="payTimePick" name="createTimePick" start-element="#payBeginTime"
                                       end-element="#payEndTime" placeholder="开始时间-结束时间" style="width: 377px;"/>
                                <input type="hidden" th:value="*{payBeginTime}" id="payBeginTime" name="payBeginTime"/>
                                <input type="hidden" th:value="*{payEndTime}" id="payEndTime" name="payEndTime"/>
                            </div>
                        </div>
                        <p style="height: 20px;"></p>
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="createTimePick">创建时间：</label>
                                <input readonly type="text" class="form-control input-sm mb10 data-range-pick"
                                       id="createTimePick" name="createTimePick" start-element="#beginTime"
                                       end-element="#endTime" placeholder="开始时间-结束时间" style="width: 377px;"/>
                                <input type="hidden" th:value="*{beginTime}" id="beginTime" name="beginTime"/>
                                <input type="hidden" th:value="*{endTime}" id="endTime" name="endTime"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="orderHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="orderHandler.searchAll()"
                                        class="btn btn-primary btn-sm m-b-none">显示全部
                                </button>
                            </div>

                            <div style="float: right" class="form-group m-r-sm">
                                <button type="button" onclick="orderHandler.exportModalShow()"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">批量导出
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"
                            th:class="${condition.deliverStatus==-1&&condition.payStatus==-1?'active':''}">
                            <a th:href="@{/order/list}" href="#">全部</a>
                        </li>
                        <li th:class="${condition.payStatus==0?'active':''}">
                            <a th:href="@{/order/list(payStatus=0)}">待支付</a>
                        </li>
                        <li th:each="deliverStatus:${deliverStatuses}"
                            th:class="${condition.deliverStatus==deliverStatus.code?'active':''}">
                            <a th:href="@{/order/list(deliverStatus=${deliverStatus.code})}"
                               th:text="${deliverStatus.desc}">买家待收货</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">
                                <table class="table table-bordered table-hover table-center" th:each="order:${orders}">
                                    <thead>
                                    <tr>
                                        <th colspan="12" style="color: #636e7b; padding-bottom: 0px; text-align: left;">
                                            <a th:href="|javascript:orderHandler.openShop(${order.merchantPO.merchantId})|">
                                                <span th:text="${order.merchantPO.data.title}">淘气店铺</span>
                                                &nbsp;</a>
                                            <a th:href="|javascript:orderHandler.detail('${order.subOrderId}')|"
                                               th:text="${order.subOrderId}">2019898878798</a>

                                            <th:block th:if="${order.status.code==0}">
                                                <span class="color-primary" th:text="${order.orderPO.payStatus.desc}"
                                                      th:class="${order.orderPO.payStatus.statusClass()}">已支付</span>
                                                <span class="color-warning" th:if="${order.orderPO.payStatus.code == 1}"
                                                      th:text="${order.deliverStatus.desc}"
                                                      th:class="${order.deliverStatus.statusClass()}">待发货</span>
                                            </th:block>
                                            <th:block th:if="${order.status.code!=0&&order.status.code!=3}">
                                                <span class="color-danger"
                                                      th:text="${order.status.desc}">已取消</span>
                                            </th:block>
                                            <th:block th:if="${order.status.code==3}">
                                                <span class="color-primary">交易完成</span>
                                            </th:block>
                                            <th:block th:if="${order.showAfterStatus()!=null}">
                                                <span class="color-danger" th:text="${order.showAfterStatus().desc}">售后申请中</span>
                                            </th:block>

                                            <p style="float: right;">
                                                <span class="glyphicon glyphicon-time" data-placement="top"
                                                      data-toggle="tooltip" data-original-title="创建时间"></span>：<span
                                                    th:text="${#temporals.format(order.createTime,'yyyy-MM-dd HH:mm:ss')}">2017-01-10 22:00:20</span>
                                                &nbsp;
                                                <th:block th:if="${order.orderPO.payStatus.code==1}">
                                                    <i class="fa fa-cny" data-placement="top" data-toggle="tooltip"
                                                       data-original-title="支付时间"></i>：<span
                                                        th:text="${#temporals.format(order.orderPO.payTime,'yyyy-MM-dd HH:mm:ss')}">2017-01-10 22:00:20</span>

                                                </th:block>
                                                &nbsp;
                                                <span sec:authorize="hasRole('ADMIN')"
                                                      class="glyphicon glyphicon-copyright-mark" data-placement="top"
                                                      data-toggle="tooltip" data-original-title="支付类型"></span>：<span>微信支付</span>
                                            </p>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tr>
                                        <td>商品</td>
                                        <td>金额</td>
                                        <td>收货人</td>
                                        <td>发货状态</td>
                                        <td sec:authorize="hasRole('ADMIN')">买家用户名</td>
                                        <td>买家留言</td>
                                        <td>备注</td>
                                        <td>操作</td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p style="width: 100%; height: 50px;">
                                                <!--商品-->
                                                <img th:src="${order.orderItemPOS.get(0).goodsInfo.thumbnail+'?x-oss-process=image/resize,l_200'}"
                                                     style="border-radius: 10px; width: 50px; height: 50px; float: left; margin-left: 5px;"
                                                     src=""/>
                                                <span th:text="${order.orderItemPOS.get(0).goodsInfo.goodsName}"
                                                      style="overflow: hidden; text-align: left; margin-left: 10px; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; width: 54%; float: left;">商品名称</span>
                                                <span style="float: right; margin-top: 30px">X<span
                                                        th:text="${order.orderItemPOS.get(0).num}">1</span></span>
                                            </p>
                                        </td>
                                        <td th:text="${order.finalAmount}">0</td>
                                        <td>
                                            <span th:if="${order.orderPO.receivingInfo!=null}"
                                                  th:text="${order.orderPO.receivingInfo.userName}"></span>
                                        </td>
                                        <td th:class="${order.deliverStatus.statusClass()}">
                                            <th:block th:if="${order.orderPO.payStatus.code == 1}"
                                                      th:text="${order.deliverStatus.desc}">
                                                已支付
                                            </th:block>
                                            <th:block th:if="${order.orderPO.payStatus.code != 1}">/</th:block>
                                        </td>
                                        <td sec:authorize="hasRole('ADMIN')" th:text="${order.orderPO.userPO.mobile}">
                                            18777876675
                                        </td>
                                        <td th:text="${order.memo}"></td>
                                        <td th:text="${order.remark}"></td>
                                        <td>
                                            <a href="javascript:orderHandler.detail('')"
                                               th:href="|javascript:orderHandler.detail('${order.subOrderId}')|">详情</a>

                                            <a sec:authorize="hasRole('MERCHANT')" th:if="${order.enableDeliver()}"
                                               href="javascript:orderHandler.deliver('')"
                                               th:href="|javascript:orderHandler.deliver('${order.subOrderId}')|">发货</a>

                                            <a sec:authorize="hasRole('ADMIN')" th:if="${order.enableReceived()}"
                                               href="javascript:orderHandler.receive('')"
                                               th:href="|javascript:orderHandler.receive('${order.subOrderId}')|">签收</a>
                                            <th:block th:if="${order.isCanConverted()}">
                                                <a sec:authorize="hasRole('ADMIN')"
                                                   th:if="${order.isReceived()&&!order.isAmountDone()}"
                                                   href="javascript:orderHandler.settled('')"
                                                   th:href="|javascript:orderHandler.settled('${order.subOrderId}')|">转正</a>
                                            </th:block>
                                        </td>
                                    </tr>
                                    <thead>
                                    <tr>
                                        <th colspan="12" style="color: #636e7b; padding-bottom: 0px; text-align: left;">
                                            <p style="float: left;">
                                                <span th:text="${order.orderType.desc}">普通订单</span>
                                                <span class="color-danger"
                                                      th:if="${order.liveSessionId!=null&&order.liveSessionId!=''}">
                                                    （直播）
                                                </span>
                                                <span sec:authorize="hasRole('ADMIN')">订单来源:</span>
                                                <span sec:authorize="hasRole('ADMIN')"
                                                      th:text="${order.orderPO.getSystemInfo().client+';'+order.orderPO.getSystemInfo().systemInfo}">--</span>
                                            </p>
                                            <p style="float: right;">
                                                商品数量：<span th:text="${order.goodsNum}">1</span>
                                                <th:block sec:authorize="hasRole('ADMIN')">
                                                    实付金额：￥<span th:text="${order.finalAmount}">2000.00</span>
                                                </th:block>
                                                <th:block sec:authorize="hasRole('MERCHANT')">
                                                    结算价：￥<span th:text="${order.payment()}">2000.00</span>
                                                </th:block>
                                            </p>
                                        </th>
                                    </tr>
                                    </thead>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="export_modal">
    <div class="form-horizontal" style="width: 479px;">
        <div class="form-group form-inline">
            <label class="col-sm-4 control-label">*起始页：</label>
            <div class="col-sm-8">
                <input type="number" id="export_beginPage" min="1" th:max="${totalPages}" value="1" required
                       class="form-control input-sm input-s only-number">
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group form-inline">
            <label class="col-sm-4 control-label">*页数：</label>
            <div class="col-sm-8">
                <input type="number" id="export_pageCount" value="1" min="1" max="10" placeholder="每次导出不得超过10页" required
                       class="form-control input-sm input-s only-number">
            </div>
        </div>
    </div>
</script>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316?1234567"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316(123)}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/order/list}]]*/  "";
    const exportUri = /*[[@{/order/export}]]*/  "";
    const detailUri = /*[[@{/order/detail}]]*/  "";
    const deliverUri = /*[[@{/order/deliver}]]*/  "deliver.html";
    const apiUri = /*[[@{/order}]]*/  "deliver.html";
</script>

<script>
    var exportModal = $("#export_modal").modal("导出当前筛选结果集", function () {
        let beginPage = $("#export_beginPage").val();
        let pageCount = $("#export_pageCount").val();
        let formData = $('#searchForm').serializeArray();

        if (typeof pageCount == "undefined" || pageCount === '' || isNaN(pageCount)) {
            pageCount = 1;
        }

        let params = "?beginPage=" + beginPage + "&pageCount=" + parseInt(pageCount);
        $.each(formData, function (o, item) {
            if (!hot.isNullOrEmpty(item.value)) {
                params += "&" + item.name + "=" + item.value;
            }
        });
        let uri = exportUri + params;

        window.open(uri);
    });

    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            orderHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });

    var orderHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        detail: function (orderId) {
            hot.newTab(detailUri + "?orderId=" + orderId, "订单详情-" + orderId);
        },
        deliver: function (orderId) {
            hot.iframeModal(deliverUri + "?orderId=" + orderId, "900px", "500px", '订单发货');
        },
        exportModalShow: function () {
            exportModal.show();
        },
        receive: function (subOrderId) {
            hot.confirm("确认签收？", function () {
                hot.ajax(apiUri + "/receive", {
                    subOrderId: subOrderId
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    }
                }, function () {
                }, "post", 300)
            });
        },
        settled: function (subOrderId) {
            hot.confirm("确认转正？", function () {
                hot.ajax(apiUri + "/settled", {
                    subOrderId: subOrderId
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error(apiResult.resultMsg || "转正失败");
                    }
                }, function () {
                }, "post", 300)
            });
        },
        openShop(merchantId) {
            hot.newTab("merchant/detail?id=" + merchantId, "查看商户信息-" + merchantId);
        }
    };
</script>
</body>
</html>
